<template>
  <div class="public_telephone_configuration">
        <div class="header_title">
            <span>公话配置</span>
        </div>
        <div class="list_info">
            <el-form ref="elform" :model="elform" :rules="elformrule"  :label-position="labelPosition" label-width="120px" >
                <el-form-item label="当前可用分钟:" prop="availableSeconds">
                    <el-col :span="4">
                        <el-input v-model="elform.availableSeconds" size="mini" disabled><i  slot="suffix" style="font-style:normal;margin-right: 10px;">分</i></el-input>
                    </el-col>   
                </el-form-item>
                <el-form-item label="费率:" prop="rate">
                    <el-col :span="4">
                        <el-input v-model="elform.rate" size="mini" ><i  slot="suffix" style="font-style:normal;margin-right: 10px;">元/分钟</i></el-input>
                    </el-col>   
                </el-form-item>
                <el-form-item label="终端价格:" prop="terminalPrice">
                    <el-col :span="4">
                        <el-input v-model="elform.terminalPrice" size="mini" ><i  slot="suffix" style="font-style:normal;margin-right: 10px;">元</i></el-input>
                    </el-col>   
                </el-form-item>
                <el-form-item label="赠送时间分钟:" prop="givingMinutes">
                    <el-col :span="4">
                        <el-input v-model="elform.givingMinutes" size="mini" ><i  slot="suffix" style="font-style:normal;margin-right: 10px;">分钟</i></el-input>
                    </el-col>   
                </el-form-item>
                <el-form-item label="警告阈值分钟:" prop="warningThreshold">
                    <el-col :span="4">
                        <el-input v-model="elform.warningThreshold" size="mini" ><i  slot="suffix" style="font-style:normal;margin-right: 10px;">分钟</i></el-input>
                    </el-col>   
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="onSubmit()">保存信息</el-button>
                </el-form-item>    
            </el-form>     
        </div>
  </div>
</template>

<script>
export default {
    data() {
        return {
            elform:{
                availableSeconds:'',
                rate:'',
                terminalPrice:'',
                givingMinutes:'',
                warningThreshold:'',
                agentGuid:''
            },
            elformrule:{},
            labelPosition:'right',
        }
    },
    computed: {
        changeschoolid: {
          get() {
            return this.$store.state.user.changeschoolid;
          }
        }
    },
    created() {
    },
    mounted() {
        this.getagentinit()
    },
    methods: {
        //获取代理商信息
        getagentinit(){
            this.$http({
                url: this.$http.adornUrl("/voip/agent/info"),
                method: "post",
                data: this.$http.adornData({
                  messageContent:this.changeschoolid,
                  messageType:0
                })
                })
                .then(({ data }) => {
                    console.log(data)
                if(data.messageCode===200){
                    this.elform.availableSeconds=parseFloat(data.messageContent.availableSeconds / 60)
                    this.elform.rate=parseFloat(data.messageContent.rate)
                    this.elform.terminalPrice=parseFloat(data.messageContent.terminalPrice)
                    this.elform.givingMinutes=parseFloat(data.messageContent.givingMinutes)
                    this.elform.warningThreshold=parseFloat(data.messageContent.warningThreshold)
                }else{
                    this.$message({
                        showClose: true,
                        message: data.errorMessage,
                        type: "error"
                    });
                }
            });
        },
        //保存
        onSubmit(){
            this.elform.unitGuid=this.changeschoolid
            let arr = {...this.elform}
            delete arr.availableSeconds
            this.$http({
                url: this.$http.adornUrl("/voip/agent/update-agent"),
                method: "post",
                data: this.$http.adornData({
                  messageContent:arr,
                  messageType:0
                })
                })
                .then(({ data }) => {
                 if(data.messageCode == 200) {
                    this.$message({
                      showClose: true,
                      message: '配置成功',
                      type: 'success'
                   });
                   this.getagentinit()
                 }else{
                     this.$message.error(data.errorMessage)
                }
            })
        }
    },
}
</script>

<style lang="scss" scoped>
.public_telephone_configuration{
    padding: 10px;
    .header_title{
        padding-left: 22px;
        height: 50px;
        line-height: 50px;
        border-bottom: 1px solid #e5e9f2;
        color:#909399;
    }
    .list_info{
        font-size: 16px;
        font-weight: bold;
        color: #909399;
        padding-top: 20px;
        .el-form-item{
            padding-left: 22px;
            height: 50px;
            line-height: 50px;
            margin-bottom: 0px;
            width: 100%;
        }
    }
}
</style>